package org.timeticker;

import java.io.IOException;
import java.io.Reader;

/**
 * @author Ivan Latysh
 * @version 0.1
 * @since 16-Jul-2007 : 8:44:56 PM
 */
public class IOHelper {

  /**
   * Fully read given reader into string buffer using 1k intermediate buffer
   *
   * @param reader reader to read
   * @return StringBuffer
   * @throws java.io.IOException when IO Exception occured
   */
  public static StringBuffer getStringFromReader(Reader reader) throws IOException {
    // buffer
    char[] buf = new char[1024];
    // read into StringBuilder
    StringBuffer sb = new StringBuffer();
    // read fully
    for (int read = reader.read(buf); read>0; read = reader.read(buf)) {
      sb.append(buf, 0, read);
    }
    // return
    return sb;
  }

}
